package tai

import (
	"github.com/spf13/viper"
	asr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/asr/v20190614"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	nlp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/nlp/v20190408"
	tts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tts/v20190823"
)

func GetCredential() *common.Credential {
	Credential := common.NewCredential(
		viper.GetString("tai.secretId"),
		viper.GetString("tai.secretKey"),
	)
	return Credential
}

func GetNlpClient() (*nlp.Client, error) {
	credential := GetCredential()
	cpf := profile.NewClientProfile()
	cpf.HttpProfile.Endpoint = viper.GetString("tai.httpEndpoint")
	cpf.Debug = viper.GetBool("tai.debug")
	client, err := nlp.NewClient(credential, viper.GetString("tai.region"), cpf)
	return client, err
}

func GetAsrClient() (*asr.Client, error) {
	cpf := profile.NewClientProfile()
	cpf.HttpProfile.Endpoint = "asr.tencentcloudapi.com"
	cpf.Debug = viper.GetBool("tai.debug")
	return asr.NewClient(GetCredential(), "", cpf)
}

func GetTtsClient() (*tts.Client, error) {
	cpf := profile.NewClientProfile()
	cpf.HttpProfile.Endpoint = "tts.tencentcloudapi.com"
	cpf.Debug = viper.GetBool("tai.debug")
	return tts.NewClient(GetCredential(), "ap-guangzhou", cpf)
}
